package cate.game.pvp.arena;

import cate.common.table.common.CommonExcel;
import cate.common.table.d.GDParamTool;
import easy.java.dev.note.NoteField;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.*;

@Slf4j
@UtilityClass
public final class ArenaConstants {
    @NoteField("开启挑战的周天数")
    public static Set<Integer> OPEN_WEEK_DAYS = new HashSet<>();
    @NoteField("开启提示")
    public static String OPEN_NOTICE;
    @NoteField("每日免费挑战次数")
    public static int FREE_FIGHT_DAILY = 1;
    @NoteField("挑战消耗物品")
    public static String FIGHT_COST_STR = "3:206004:3";
    @NoteField("每日点赞次数")
    public static int LIKE_TIME_DAILY = 3;
    @NoteField("点赞奖励")
    public static String LIKE_REWARD = "0:13:50";
    @NoteField("刷新对手CD")
    public static long REFRESH_OPPONENT_CD = 10L;
    @NoteField("初始积分")
    public static int INIT_SCORE = 1000;
    @NoteField("跨赛季积分折扣(万分比)")
    public static int SEASON_DISCOUNT = 7000;
    @NoteField("胜利基础积分变化")
    public static int BASE_SCORE_CHANGE = 15;
    @NoteField("胜利额外分差系数(万分比)")
    public static int EXTRA_SCORE_CHANGE_RATE = 300;
    @NoteField("排行奖励邮件")
    public static int RANK_MAIL_ID = 100124;
    @NoteField("排行奖励邮件-EX")
    public static int RANK_MAIL_ID_EX = 100179;
    @NoteField("前X名需要隐藏2队")
    public static int HIDE_2_RANK = 30;
    @NoteField("领取额外挑战奖励的消耗")
    public static String EXTRA_FIGHT_REWARD_COST = "0:2:50";
    @NoteField("最大战报记录数")
    public static int RECORD_NUM_MAX = 10;

    /**
     * 从配置中读取常量
     *
     * @param common 通用配置
     */
    public static void loadFromTable(CommonExcel common) {
        // 策划配常量表
        String weekDaysStr = GDParamTool.getString(common.param, 550, "2#4#6");
        List<String> notices = new ArrayList<>();
        try {
            OPEN_WEEK_DAYS.clear();
            String[] splits = weekDaysStr.split("#");
            for (String s : splits) {
                OPEN_WEEK_DAYS.add(Integer.parseInt(s));
                notices.add(parseWeekDayCN(s));
            }
        } catch (Exception e) {
            log.error("", e);
        }
        OPEN_NOTICE = String.format("每周%s开启玩法", StringUtils.join(notices, "、"));
        FREE_FIGHT_DAILY = GDParamTool.getInt(common.param, 551, FREE_FIGHT_DAILY);
        FIGHT_COST_STR = GDParamTool.getString(common.param, 552, FIGHT_COST_STR);
        LIKE_TIME_DAILY = GDParamTool.getInt(common.param, 553, LIKE_TIME_DAILY);
        LIKE_REWARD = GDParamTool.getString(common.param, 554, LIKE_REWARD);
        REFRESH_OPPONENT_CD = GDParamTool.getLong(common.param, 555, REFRESH_OPPONENT_CD);
        INIT_SCORE = GDParamTool.getInt(common.param, 556, INIT_SCORE);
        SEASON_DISCOUNT = GDParamTool.getInt(common.param, 557, SEASON_DISCOUNT);
        BASE_SCORE_CHANGE = GDParamTool.getInt(common.param, 558, BASE_SCORE_CHANGE);
        EXTRA_SCORE_CHANGE_RATE = GDParamTool.getInt(common.param, 559, EXTRA_SCORE_CHANGE_RATE);
        RANK_MAIL_ID = GDParamTool.getInt(common.param, 560, RANK_MAIL_ID);
        HIDE_2_RANK = GDParamTool.getInt(common.param, 561, HIDE_2_RANK);
        EXTRA_FIGHT_REWARD_COST = GDParamTool.getString(common.param, 562, EXTRA_FIGHT_REWARD_COST);
        RECORD_NUM_MAX = GDParamTool.getInt(common.param, 563, RECORD_NUM_MAX);
    }

    /**
     * 数字周天转中文
     */
    private static String parseWeekDayCN(String s) {
        switch (s) {
            case "1":
                return "一";
            case "2":
                return "二";
            case "3":
                return "三";
            case "4":
                return "四";
            case "5":
                return "五";
            case "6":
                return "六";
            case "7":
                return "日";
            default:
                return "?";
        }
    }

    /**
     * 构建默认布阵视野
     *
     * @param rank 排名
     */
    public static List<Boolean> BUILD_DEFAULT_VISION(int rank) {
        if (rank == 0 || rank > HIDE_2_RANK) {
            return Arrays.asList(true, false, false);
        }
        return Arrays.asList(true, true, false);
    }
}
